package com.etonedu.meals.utils;

import com.etonedu.meals.http.HttpUrl;
import com.google.common.base.Charsets;
import com.google.common.base.Joiner;
import com.google.common.hash.Hashing;

public class MD5Utils {
    // 测试
    public static final String CLI_CODE = "SUe3Wk804EN0hXvXlqNx";
    public static final String SIGN_KEY = "6mBfkYmXPb512NRxrimRycGm7ESHMSCr1aXAJv6t3jCtKueliA";
    public static final String ENCRY_DECRYPT_KEY = "kFC6YWKO74lAcwMcR9xXU7Be";
    // 生产
    public static final String PROD_CLI_CODE = "SUe3Wk804EN0hXvXlqNx";
    public static final String PROD_SIGN_KEY = "XK9k00XtlBRudUPapB6W5si7B63RNG3m7lhhbiMVkzexprfg";
    public static final String PROD_ENCRY_DECRYPT_KEY = "i6wjtV8UuJ5AIBuTN82zaYcmHdpZIZhS";

    public static String getParams(String timestamp,String ip,String cid) {
        if (HttpUrl.DOMAIN.equals("http://agw.52ess.cn/api") || HttpUrl.DOMAIN.equals("http://47.106.165.234:8181/api")) {
            String hashStr = Joiner.on("").skipNulls().join(timestamp, ip, cid, CLI_CODE, SIGN_KEY);

            String authHashcode = Hashing.md5().hashString(hashStr, Charsets.UTF_8).toString();
            return authHashcode;
        } else if (HttpUrl.DOMAIN.equals("http://agw.woniukid.cn/api")) {
            String hashStr = Joiner.on("").skipNulls().join(timestamp, ip, cid, PROD_CLI_CODE, PROD_SIGN_KEY);

            String authHashcode = Hashing.md5().hashString(hashStr, Charsets.UTF_8).toString();
            return authHashcode;
        } else if (HttpUrl.DOMAIN.equals(HttpUrl.DOMAIN.equals("http://47.106.165.234:8181/api"))) {
            String hashStr = Joiner.on("").skipNulls().join(timestamp, ip, cid, CLI_CODE, SIGN_KEY);

            String authHashcode = Hashing.md5().hashString(hashStr, Charsets.UTF_8).toString();
            return authHashcode;
        } else if (HttpUrl.DOMAIN.equals("http://123.207.103.39:8080/api")) {
            String hashStr = Joiner.on("").skipNulls().join(timestamp, ip, cid, PROD_CLI_CODE, PROD_SIGN_KEY);

            String authHashcode = Hashing.md5().hashString(hashStr, Charsets.UTF_8).toString();
            return authHashcode;
        } else {
            return "";
        }

    }

    public static String t(String data,String time) {
        if (HttpUrl.DOMAIN.equals("http://agw.52ess.cn/api") || HttpUrl.DOMAIN.equals("http://47.106.165.234:8181/api")) {
            String hashStr = Joiner.on("").skipNulls().join(CLI_CODE, SIGN_KEY, data, time);
            String authHashcode = Hashing.md5().hashString(hashStr, Charsets.UTF_8).toString();
            return authHashcode;
        } else if (HttpUrl.DOMAIN.equals("http://agw.woniukid.cn/api") || HttpUrl.DOMAIN.equals("http://123.207.103.39:8080/api")) {
            String hashStr = Joiner.on("").skipNulls().join(PROD_CLI_CODE, PROD_SIGN_KEY, data, time);
            String authHashcode = Hashing.md5().hashString(hashStr, Charsets.UTF_8).toString();
            return authHashcode;
        } else {
            return "";
        }
    }
}
